﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ShadowEraDeckEditor
{
    public class DeckCode
    {

        //string is encoded deck, int i is size of deck array
        //returns a deck code from a deckArray
        public static int[] CtoINT(string s,int i)
        {
            int[] deckArray;
            deckArray = new int[i];
            if (s != null)
            {
                s = Crypto.Decrypt(s);
                string[] iCards = s.Split(',');
                foreach (string iCard in iCards)
                {
                    deckArray[Convert.ToInt16(iCard)]++;
                }
            }
            return deckArray;
        }

        //int i[] is a deckArray
        //returns a Deck Code from a deckArray
        public static string INTtoC(int[] i)
        {
            string buffer = "";
            for (int z = 0; z < i.Length; z++)
            {
                if (i[z] > 0)
                {
                    for (int x = 0; x < i[z]; x++)
                    {
                        buffer += z.ToString();
                        buffer += ",";
                    }
                }
            }
            buffer = buffer.TrimEnd(',');
            buffer = Crypto.Encrypt(buffer);
            return buffer;
        }

        public static bool Verify(string s)
        {
            s = Crypto.Decrypt(s);
            string[] iCards = s.Split(',');
            int i = 0;
            foreach (string iCard in iCards)
            {
                i++;
            }   
            if (i > 29)
                return true;
            else
                return false;
        }
    } 
}
